<template>
  <div class="body">
    <el-container>
      <!-- 头部导航栏 -->
      <el-header>
        <Index></Index>
      </el-header>
      <!-- 左侧边栏 -->

      <el-container>
        <el-container>
          <el-main>
            <el-tabs v-model="activeName" @tab-click="handleClick">
              <el-tab-pane label="用网电价" name="first">
              
                <el-row class="el-row2">
                  <el-table
                    :data="tableData"
                    style="width: 90%;margin-left:100px;margin-top:50px;"
                    :row-style="getRowClass"
                    :header-row-style="getRowClass"
                    :header-cell-style="getRowClass2"
                    :row-class-name="tableRowClassName"
                  >
                    <el-table-column prop="name1" label="名称">
                    </el-table-column>
                    <el-table-column prop="name2" label="时间">
                    </el-table-column>
                      <el-table-column prop="name3" label="电价">
                    </el-table-column>
                       <el-table-column
      fixed="right"
      label="操作"
     >
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
        <el-button type="text" size="small" @click="dialogVisible = true">编辑</el-button>
      </template>
    </el-table-column>
                   
                  </el-table>
                </el-row>
              </el-tab-pane>
              <el-tab-pane label="上网电价" name="second">
              
                <el-row class="el-row2">
                  <el-table
                    :data="tableData"
                    style="width: 90%;margin-left:100px;margin-top:50px;"
                    :row-style="getRowClass"
                    :header-row-style="getRowClass"
                    :header-cell-style="getRowClass2"
                    :row-class-name="tableRowClassName"
                  >
                    <el-table-column prop="name1" label="名称">
                    </el-table-column>
                    <el-table-column prop="name2" label="时间">
                    </el-table-column>
                      <el-table-column prop="name3" label="电价">
                    </el-table-column>
                      <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
        <el-button type="text" size="small" @click="dialogVisible = true">编辑</el-button>
      </template>
    </el-table-column>
                   
                  </el-table> </el-row
              ></el-tab-pane>
              <el-tab-pane label="供气价格" name="third">
              
                <el-row class="el-row2">
                  <el-table
                    :data="tableData"
                    style="width: 90%;margin-left:100px;margin-top:50px;"
                    :row-style="getRowClass"
                    :header-row-style="getRowClass"
                    :header-cell-style="getRowClass2"
                    :row-class-name="tableRowClassName"
                  >
                     <el-table-column prop="name1" label="名称">
                    </el-table-column>
                    <el-table-column prop="name2" label="时间">
                    </el-table-column>
                      <el-table-column prop="name3" label="电价">
                    </el-table-column>
                    <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
        <el-button type="text" size="small" @click="dialogVisible = true">编辑</el-button>
      </template>
    </el-table-column>
                   
                  </el-table> </el-row
              ></el-tab-pane>
             
                <el-tab-pane label="供水价格" name="fourth">
             
                <el-row class="el-row2">
                  <el-table
                    :data="tableData"
                    style="width: 90%;margin-left:100px;margin-top:50px;"
                    :row-style="getRowClass"
                    :header-row-style="getRowClass"
                    :header-cell-style="getRowClass2"
                    :row-class-name="tableRowClassName"
                  >
                     <el-table-column prop="name1" label="名称">
                    </el-table-column>
                    <el-table-column prop="name2" label="时间">
                    </el-table-column>
                      <el-table-column prop="name3" label="电价">
                    </el-table-column>
                       <el-table-column
      fixed="right"
      label="操作"
      width="100">
      <template slot-scope="scope">
        <el-button @click="handleClick(scope.row)" type="text" size="small">查看</el-button>
        <el-button type="text" size="small" @click="dialogVisible = true">编辑</el-button>
      </template>
    </el-table-column>
                   
                  </el-table> </el-row
              ></el-tab-pane>
              </el-row
              ></el-tab-pane>
            </el-tabs>
          </el-main>
        </el-container>
      </el-container>

      <!-- 表格显示区 -->

      <Bottom></Bottom>
    </el-container>
    <el-dialog
  title="提示"
  :visible.sync="dialogVisible"
  width="30%"
  :before-close="handleClose">
 <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
  <el-form-item label="名称">
    <el-input v-model="formLabelAlign.name"></el-input>
  </el-form-item>
  <el-form-item label="时间">
    <el-input v-model="formLabelAlign.region"></el-input>
  </el-form-item>
  <el-form-item label="电价">
    <el-input v-model="formLabelAlign.type"></el-input>
  </el-form-item>
</el-form>
  <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="handleClose()">确 定</el-button>
  </span>
</el-dialog>
  </div>
  
</template>
<script>
import echarts from 'echarts'
// import MyCircle from '../components/MyCircle.vue'
import { Topology } from 'topology-core'
import { Node } from 'topology-core/models/node'
import { Line } from 'topology-core/models/line'
import * as FileSaver from 'file-saver'

import { Tools, canvasRegister } from '~/services/canvas'

import CanvasProps from '~/components/CanvasProps'
import CanvasContextMenu from '~/components/CanvasContextMenu'
import Index from '~/components/index2'
import Bottom from '~/components/bottom'
export default {
  data() {
    return {
      labelPosition: 'right',
        formLabelAlign: {
          name: 'AC_IN上网电价',
          region: '01.15.00',
          type: '1.111'
        },
      
  dialogVisible: false,
     options: [
        {
          value: '选项1',
          label: '电锅炉计量'
        },
        {
          value: '选项2',
          label: '交流计量-红外补温'
        },
        {
          value: '选项3',
          label: '交流计量空间电场除湿'
        },
        {
          value: '选项4',
          label: '卷窗帘计量'
        },
        {
          value: '选项5',
          label: '水肥一体机'
        },
        {
          value: '选项6',
          label: '直流多路计量LED东'
        },
        {
          value: '选项7',
          label: '直流多路计量LED西'
        },
        {
          value: '选项8',
          label: '直流多路计量物理杀虫'
        }
      ],
      value: '',

     
      tableData: [
        {
          name1: '高峰时段1',
          name2: '08:00:00-11:30:00',
          name3:'0.6714'
          
        },
        {
         name1: '平段1',
          name2: '11:30:00-15:00:00',
           name3:'0.4489'
        },
       {
          name1: '高峰时段2',
          name2: '15:00:00-16:00:00',
           name3:'0.6714'
          
        },
        {
         name1: '平段2',
          name2: '16:00:00-18:30:00',
           name3:'0.4489'
          
        },
        {
          name1: '高峰时段3',
          name2: '18:00:00-22:00:00',
           name3:'0.2265'
          
        },
        {
         name1: '平段3',
          name2: '22:00:00-23:00:00',
           name3:'0.6714'
          
        },
       {
          name1: '低估时段',
          name2: '23:00:00-00:07:00',
           name3:'0.6714'
          
        },
        {
         name1: '平段4',
          name2: '00:07:00-00:08:00',
           name3:'0.6714'
          
        },
      ],
      tools: Tools,
      canvas: {},
      canvasOptions: {
        rotateCursor: '/img/rotate.cur'
      },
      props: {
        a: null,
        node: null,
        line: null,
        nodes: null,
        multi: false,
        locked: false
      },
      contextmenu: {
        left: null,
        top: null,
        bottom: null
      },

      labelPosition: 'left',
      

      // icon: require('@/assets/images/onlinecar.png'),
      activeIndex: '3',

      activeName: 'first',

      center: { lng: 116.404, lat: 39.915 },
      zoom: 12,
      scroll: true,
      value: ''
    }
  },
  components: {
    CanvasProps,
    CanvasContextMenu,
    Index,
    Bottom
  },
  computed: {
    event() {
      return this.$store.state.event.event
    }
  },
  watch: {
    event(curVal) {
      if (this['handle_' + curVal.name]) {
        this['handle_' + curVal.name](curVal.data)
      }
    },
    $route(val) {
      this.open()
    }
  },
  created() {
    canvasRegister()
    //控制鼠标右键点击的面板当点击空白处时消失
    if (process.client) {
      document.onclick = event => {
        this.contextmenu = {
          left: null,
          top: null,
          bottom: null
        }
      }
    }
  },

  mounted() {
 
  },

  methods: {
    handleClose(done) {
      
        this.$confirm('确认保存数据？')
          .then(_ => {
            done();
          })
          .catch(_ => {});
          this.dialogVisible = false;
      },
    async open() {
      if (!this.$route.query.id) {
        return
      }
      const data = await this.$axios.$get(
        '/api/topology/' + this.$route.query.id
      )
      if (data && data.id) {
        this.canvas.open(data.data)
      }
    },
    getRowClass({ row, column, rowIndex, columnIndex }) {
      return 'background:#063432;color:#FEFEFE;'
    },
    //设置表头颜色和背景
    getRowClass2({ row, column, rowIndex, columnIndex }) {
      return 'background:#063432;color:#FEFEFE;'
    },
    handleDelete(index, row) {
      alert(index)
      //  this.$router.push({path:'/details',query: {id:item.device_id}})
      this.$router.push({ path: '/indexx' })
      console.log(index, row)
    },
    handleClick(tab, event) {
      console.log(tab, event)
    },

    logout() {
      window.sessionStorage.clear()
      this.$router.push('/login')
    },
    handleSelect(key, keyPath) {
      console.log(key, keyPath)
    },

    infoWindowClose(i) {
      //  alert("关闭提示窗"+i.showFlag)
      return (i.showFlag = false)
    },
    infoWindowOpen(i) {
      // alert("打开提示窗"+i.showFlag)
      return (i.showFlag = true)
    },
    opencarinfo(item) {
      //  this.$router.push({name:'details',params: {id:'1'}})
      // alert("执行")

      this.$router.push({ path: '/details', query: { id: item.device_id } })
    },

    handle_new(data) {
      this.canvas.open({ nodes: [], lines: [] })
    },

    handle_open(data) {
      this.handle_replace(data)
    },

    handle_replace(data) {
      const input = document.createElement('input')
      input.type = 'file'
      input.onchange = event => {
        const elem = event.srcElement || event.target
        if (elem.files && elem.files[0]) {
          const name = elem.files[0].name.replace('.json', '')
          const reader = new FileReader()
          reader.onload = e => {
            const text = e.target.result + ''
            try {
              const data = JSON.parse(text)
              if (
                data &&
                Array.isArray(data.nodes) &&
                Array.isArray(data.lines)
              ) {
                this.canvas.open(data)
              }
            } catch (e) {
              return false
            }
          }
          reader.readAsText(elem.files[0])
        }
      }
      input.click()
    },

    handle_save(data) {
      FileSaver.saveAs(
        new Blob([JSON.stringify(this.canvas.data)], {
          type: 'text/plain;charset=utf-8'
        }),
        // `le5le.topology.json`
        `11111.json`
      )
    },

    handle_savePng(data) {
      this.canvas.saveAsImage('le5le.topology.png')
    }
  }
}
</script>
<style lang="scss">
.el-tabs {
  color: white;
  background-color: #050e11;
}
.el-tabs__item {
  padding: 0 20px;
  height: 40px;
  box-sizing: border-box;
  line-height: 40px;
  display: inline-block;
  list-style: none;
  font-size: 14px;
  font-weight: 500;
  color: #e3e5ea;
  position: relative;
}
</style>
<style lang="scss" scoped>
.body {
  width: 100%;
  
 background-color:#050E11;
  // background-image: url(../../assets/images/新UI37.png);
  // background-size:100% 100%;
  // background-repeat: no-repeat;
}
.el-row1 {
  width: 100%;
  
  background-image: url(../../assets/images/新UI53.png);
   background-size:100% 100%;
  background-repeat: no-repeat;
}
.el-row2 {
  width: 100%;
 
  background-image: url(../../assets/images/新UI53.png);
   background-size:100% 100%;
  background-repeat: no-repeat;
}
.el-tabs {
  color: white;
  background-color: #050e11;
}
.el-tabs__item {
  padding: 0 20px;
  height: 40px;
  box-sizing: border-box;
  line-height: 40px;
  display: inline-block;
  list-style: none;
  font-size: 14px;
  font-weight: 500;
  color: #e3e5ea;
  position: relative;
}
#topology-canvas {
  width: 910px;
  height: 333px;
  background-image: url(../../assets/images/新UI16.png);
   background-size:100% 100%;
}
//控制画布的大小
.full {
  flex: 1;
  width: initial;
  position: relative;
  overflow: auto;
  background: #fff;
  // background-image: url("+require('../assets/images/timg.jpg')")
}

// #table1 {
//   width: 100%;
//   height: 388px;

//   // background-image: url(../../assets/images/新UI45.png);
//   // background-size: 100%;
//   // background-repeat: no-repeat;
// }

// #table2 {
//   width: 1700px;
//   height: 388px;
// }

// #table3 {
//   width: 1700px;
//   height: 388px;
// }
// #table4 {
//   width: 1700px;
//   height: 388px;
//   // margin-top: 40px;
//   // margin-left: 60px;
//   // padding-left: 0px;
// }
// #allmap {
//   // height: 600px;
//   // color: white;
//   margin-top: 20px;
// }
.newbutton {
  width: 284px;
  height: 48px;
  background-image: url(../../assets/images/新UI43.png);
  // border-color: #041214;

  display: inline-block;
}


// .el-row {
//   margin-bottom: 20px;
//   &:last-child {
//     margin-bottom: 0;
//   }
// }
// .el-col {
//   border-radius: 4px;
// }
// .bg-purple-dark {
//   background: #99a9bf;
// }
// .bg-purple {
//   background: #d3dce6;
// }
// .bg-purple-light {
//   background: #e5e9f2;
// }
// .grid-content {
//   border-radius: 4px;
//   min-height: 36px;
// }
// .row-bg {
//   padding: 10px 0;
//   background-color: #f9fafc;
// }
</style>
